package com.hx.er.common.test;

import java.util.Scanner;


public class DbFieldToBeanField {
	private static Scanner scanner;
	private static StringBuilder sbDbSelect = new StringBuilder();
	private static StringBuilder sbJavaBean = new StringBuilder();
	private static StringBuilder sbDbInsert1 = new StringBuilder();
	private static StringBuilder sbDbInsert2 = new StringBuilder();
//	private static StringBuilder sbDbUpdate = new StringBuilder();

	public static void main(String[] args) {
		scanner = new Scanner(System.in);
		System.out.println("请输入要转化的字段列表：");

		while (scanner.hasNextLine()) {
			String fieldString = scanner.nextLine();
			if (StringUtil.isEqual(fieldString, "out")) {
				System.out.println("javabean：");
				System.out.println(sbJavaBean.toString());
				System.out.println("查询语句:");
				System.out.println(sbDbSelect.toString());
				System.out.println("插入语句");
				System.out.println(sbDbInsert1.toString() + "\r\n) VALUES (\r\n" + sbDbInsert2.toString());
				return;
			}

			sbJavaBean.append("private String ");
			sbDbSelect.append(fieldString);
			sbDbSelect.append(" AS ");
			sbDbInsert1.append(fieldString);
			sbDbInsert1.append(",");
			sbDbInsert2.append("#{");

			String[] values = fieldString.split("_");
			for (int i = 0; i < values.length; i++) {
				if (i == 0) {
					sbJavaBean.append(values[i].toLowerCase());
					sbDbSelect.append(values[i].toLowerCase());
					sbDbInsert2.append(values[i].toLowerCase());
				} else {
					sbJavaBean.append(StringUtil.firstCharUpperCase(values[i]));
					sbDbSelect.append(StringUtil.firstCharUpperCase(values[i]));
					sbDbInsert2.append(StringUtil.firstCharUpperCase(values[i]));
				}
			}

			sbJavaBean.append(";\r\n");
			sbDbSelect.append(",\r\n");
			sbDbInsert1.append("\r\n");
			sbDbInsert2.append("},\r\n");
		}
	}
}
